package com.toommi.refuse.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.toommi.refuse.entity.LargeRecyclePlace;
import com.toommi.refuse.entity.LargeRecyclePlaceExample;
import com.toommi.refuse.mapper.LargeRecyclePlaceMapper;
import com.toommi.refuse.service.LargeRecyclePlaceService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * @author yangg
 * @since 2019-07-31 15:24
 */
@Service
@AllArgsConstructor
public class LargeRecyclePlaceServiceImpl implements LargeRecyclePlaceService {

    private LargeRecyclePlaceMapper placeMapper;

    @Override
    public void addLargeRecyclePlace(LargeRecyclePlace largeRecyclePlace) {

        largeRecyclePlace.setId(0L);

        largeRecyclePlace.setCreateTime(System.currentTimeMillis());
        largeRecyclePlace.setUpdateTime(System.currentTimeMillis());

        placeMapper.insert(largeRecyclePlace);

    }

    @Override
    public void deleteLargeRecyclePlace(long id) {

        placeMapper.deleteByPrimaryKey(id);

    }

    @Override
    public PageInfo<LargeRecyclePlace> findLargeRecyclePlace(int pageNum, int pageSize, String keyWord) {

        PageHelper.startPage(pageNum, pageSize);

        LargeRecyclePlaceExample example = new LargeRecyclePlaceExample();
        example.createCriteria().andNameLike("%" + keyWord + "%");

        return new PageInfo<>(placeMapper.selectByExample(example));
    }
}
